/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.fatec.ppi.teste;
import java.util.Scanner;
import br.fatec.ppi.modelo.Aluno;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Thiago
 */
public class Main {
    
 public static void main(String [] args){
   
   Scanner in = new Scanner(System.in);
     
   EntityManagerFactory fabricaMotores = Persistence.createEntityManagerFactory("modelo");

   EntityManager motor = fabricaMotores.createEntityManager();
    EntityTransaction transacao= motor.getTransaction();
    
    
    
    
    int op;
    do{
        
        
        System.out.println("1 - Iserir");
        System.out.println("0 - Sair");
        System.out.print("0pcao:");
        op=in.nextInt();
        
        switch(op){
            
            case 1:  transacao.begin();
                     Aluno aluno = new Aluno();
                
                    System.out.println("Insira o ID: ");
                    aluno.setId(in.nextInt());
                    System.out.println("Insira a Idade: ");  
                    aluno.setIdade(in.nextInt());
                    System.out.println("Insira o nome: ");  
                    aluno.setNome(in.next());
                    motor.persist(aluno);
                    transacao.commit(); 
                break;
                
            case 0:
                   break;
                
             
        }
        

    }while(op != 0);
    
    
    
 }
}
